import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * 本类作者是：rjl
 * 创建于2021/11/27
 * 此类的作用是：xxxx
 */
public class Test {
    public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
        //过程中的警告在信息
        ArrayList<String> warnings = new ArrayList<>();
        //生成代码重复时，覆盖源代码
        boolean overwrite = true;
        //读取配置文件
        InputStream is = Test.class.getResourceAsStream("generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(is);
        is.close();


        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        //创建代码生成器
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        //执行生成代码
        myBatisGenerator.generate(null);
        //输出警告信息
        for (String warning : warnings) System.out.println(warning);
    }
}











































